package com.example.flowerpcback.controller;

import com.example.flowerpcback.dto.Document;
import com.example.flowerpcback.req.DocumentReq;
import com.example.flowerpcback.req.MenusReq;
import com.example.flowerpcback.req.RolesReq;
import com.example.flowerpcback.resp.*;
import com.example.flowerpcback.services.DocumentService;
import com.example.flowerpcback.services.MenusService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@RestController //这是返回接口
@RequestMapping("/document")
public class DocumentController {

    private static final Logger LOG = LoggerFactory.getLogger(DocumentController.class);

    @Resource
    private DocumentService documentService;

    @GetMapping("/list")
    public CommonResp<PageResp<DocumentResp>> list(@Valid DocumentReq req){
        CommonResp<PageResp<DocumentResp>> resp= new CommonResp<>();
        PageResp<DocumentResp> pageResp = documentService.list(req);
        resp.setData(pageResp);
        return resp;
    }

    @PostMapping("/save")
    public CommonResp<Document> save(@Valid @RequestBody DocumentReq req){
        CommonResp<Document> resp= new CommonResp<>();
        Document document = documentService.save(req);
        resp.setData(document);
        return resp;
    }

    @GetMapping("/delete")
    public CommonResp delete(@Valid DocumentReq req){
        CommonResp resp= new CommonResp<>();
        documentService.delete(req);
        return  resp;
    }
}

